#include "main.h"
#include "lvgl/lvgl.h"
#include "lv_port_disp.h"
#include "lv_port_indev.h"
#include "lv_demos.h"

#define THREAD_STACK_SIZE       512
#define THREAD_PRIORITY         25
#define THREAD_TIMESLICE        5

static rt_thread_t tid1 = RT_NULL;
static rt_thread_t tid2 = RT_NULL;

void Task_LED(void *arg){
	while(1)
	{
		bsp_LedToggle(1);
		bsp_LedToggle(2);
		rt_thread_delay(500);
	}
}

void Task_LVGL(void *arg){

    lv_init();	    /* LVGL初始化 */
    lv_port_disp_init();	/* LVGL显示屏初始化 */
    lv_port_indev_init();	/* LVGL输入设备初始化 */
    lv_demo_widgets();	/* LVGL演示程序 */
    // lv_demo_benchmark();
    while(1)
    {
        lv_timer_handler(); /* call lvgl task handler */
        rt_thread_delay(5); /* delay 5ms */
    }
}

/*
*********************************************************************************************************
*	函 数 名: main
*	功能说明: c程序入口
*	形    参: 无
*	返 回 值: 错误代码(无需处理)
*********************************************************************************************************
*/
int main(void)
{   

    bsp_Init();		/* 硬件初始化 */

    rt_kprintf("hello RT-Thread!\n");
    tid1 = rt_thread_create("led task",Task_LED,RT_NULL,THREAD_STACK_SIZE,THREAD_PRIORITY,THREAD_TIMESLICE);
    if (tid1 != RT_NULL)
    {
        rt_thread_startup(tid1);
    }
    tid2 = rt_thread_create("lvgl task",Task_LVGL,RT_NULL,4096*2,THREAD_PRIORITY,THREAD_TIMESLICE);
    if (tid2 != RT_NULL)
    {
        rt_thread_startup(tid2);
    }
        

    return 0;
}
